const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
  return sequelize.define('m_users', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true
    },
    tenant_id: {
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: '租户id'
    },
    nickname: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '登录名'
    },
    password: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '密码'
    },
    salt: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '加密盐'
    },
    tel: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '电话'
    },
    email: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '电子邮箱'
    },
    headimg: {
      type: DataTypes.STRING(500),
      allowNull: true,
      comment: '头像url'
    },
    remark: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '备注'
    },
    state: {
      type: DataTypes.SMALLINT,
      allowNull: true,
      defaultValue: 1,
      comment: '状态 0-停用 1-启用'
    },
    rights: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: '权限JSON'
    },
    hash: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '权限哈希值'
    },
    tenant_hash: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '租户权限哈希值'
    },
    create_ip: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '注册ip'
    },
    last_login_time: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '最后登录时间'
    },
    last_login_ip: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '最后登录的ip'
    },
    login_count: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '登录次数'
    },
    create_time: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: '注册时间'
    },
    create_user_id: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '创建人id'
    },
    create_user_name: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '创建人名'
    },
    modify_time: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: '修改时间'
    },
    modify_user_id: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '修改人id'
    },
    modify_user_name: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '修改人名'
    }
  }, {
    sequelize,
    tableName: 'm_users',
    timestamps: false,
    freezeTableName: true,
    indexes: [
      {
        name: 'PRIMARY',
        unique: true,
        using: 'BTREE',
        fields: [
          { name: 'id' }
        ]
      },
      {
        name: 'idx_tid_nickname',
        unique: true,
        using: 'BTREE',
        fields: [
          { name: 'tenant_id' },
          { name: 'nickname' }
        ]
      },
      {
        name: 'idx_tenant_id',
        using: 'BTREE',
        fields: [
          { name: 'tenant_id' }
        ]
      },
      {
        name: 'idx_tenant_hash',
        using: 'BTREE',
        fields: [
          { name: 'tenant_hash' }
        ]
      }
    ]
  });
};
